package com.wukang.photovoltaicinspectionpictures.logger

import android.app.Application
import com.tencent.mars.xlog.Log
import com.tencent.mars.xlog.Xlog
import java.io.File

/**
 * 日志工具
 * @author wukang
 */
object Rog {
    private const val TAG: String = "Rog"

    internal var mApplication: Application? = null

    private var DEBUG: Boolean = false

    fun init(application: Application?, isDEBUG: Boolean) {
        init(application, isDEBUG, 0)
    }

    fun init(application: Application?, isDEBUG: Boolean, cacheDays: Int) {
        init(application, isDEBUG, null, cacheDays)
    }

    fun init(application: Application?, isDEBUG: Boolean, xlog: Xlog?, cacheDays: Int) {
        mApplication = application
        DEBUG = isDEBUG
        if (null == xlog) {
            XLogManager.init(isDEBUG, cacheDays)
        } else {
            XLogManager.init(isDEBUG, xlog, cacheDays)
        }
    }

    fun readMsg(callback: (File?) -> Unit) {
        XLogManager.readMsg(callback)
    }

    fun clearMsg() {
        XLogManager.upLoadClear()
    }

    fun v(tag: String? = TAG, msg: String?) {
        Log.v(tag, msg)
        if (DEBUG) {
            android.util.Log.v(tag, msg ?: "")
        }
    }

    fun d(tag: String? = TAG, msg: String?) {
        Log.d(tag, msg)
        if (DEBUG) {
            android.util.Log.d(tag, msg ?: "")
        }
    }

    fun i(tag: String? = TAG, msg: String?) {
        Log.i(tag, msg)
        if (DEBUG) {
            android.util.Log.i(tag, msg ?: "")
        }
    }

    fun w(tag: String? = TAG, msg: String?) {
        Log.w(tag, msg)
        if (DEBUG) {
            android.util.Log.w(tag, msg ?: "")
        }
    }

    fun e(tag: String? = TAG, msg: String?) {
        Log.e(tag, msg)
        if (DEBUG) {
            android.util.Log.e(tag, msg ?: "")
        }
    }
}